package com.lovo.TestFile;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesUtils {
    /**
     * properties输出流 (写入文件)
     * @param path 保存路径
     */
    public static void writeProperties(String path,Properties p) {

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(path);
            p.store(fos, null);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * properties输入流 (读取文件)
     *  @param path 读取路径
     */
    public static void readProperties(String path,Properties p) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(path);
            p.load(fis);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}